home *** CD-ROM | disk | FTP | other *** search
/ Alles Voor Internet / Tout Pour Internet / alles voor internet.iso / MacInternet™ / Telnet / DialScript / DialScript 1.7.1 Doc / DialScript 1.7.1 Doc.rsrc / TEXT_130.txt < prev    next >
Text File  |  1994-03-08  |  7KB  |  183 lines

  1. A Complex Script, Explained
  2.  
  3. The following pages contain an example of a well-written and robust script.
  4.  
  5. This script uses most of DialScript's important features and is excessively commented in order to explain them. 
  6.  
  7. -- Comments start with --.
  8.  
  9. -- To use 1200 bps, remove the "send break", and set speed to 1200
  10. -- The script gets the modem's attention and dial, even if it has
  11. -- to hang up to do it.  It uses timeouts to recover from problems.
  12. -- Problems after connect are assumed to be due to line noise, so it
  13. -- hangs up and dials again in hope of a cleaner line.  It assumes
  14. -- a Hayes type modem set for English commands and responses.
  15.  
  16. -- You must set the variable for your username in state init and fix up
  17. -- state FinishUp (optional).
  18.  
  19. script cs    -- scripts must begin with the word "script" and a name.
  20.              -- Keywords like script must be in lower case.
  21.  
  22.    -- Execution begins with the first state in the file.  In this case,
  23.    -- the state named init.  Every state must have a unique name.     
  24.    -- Identifiers (names) in DialScript are sequences of any
  25.    -- length of letters, digits, and underscore characters.  They
  26.    -- must begin with a letter.
  27.  
  28.    state init
  29.  
  30.       -- Display statements display characters on the terminal window
  31.       -- without sending them.  Use it for user messages.  The variable
  32.       -- date contains the current date and time.  A newline is not          
  33.       -- automatically included.  Hence the display "\r" at the end.
  34.  
  35.       display "Beginning UT CS login script on\r";
  36.       display date;
  37.       display "\r";  --   <-- Don't forget semicolons after statements.
  38.  
  39.       set port modem;  -- The set statement is used to set communication
  40.       set speed 2400;  -- parameters.  These values are the defaults, so          
  41.       set databits 8;  -- these statements are not really necessary.
  42.  
  43.       set online on;   -- Be sure DialScript is online so that it will
  44.                        -- talk to the serial port.  This is also
  45.                        -- the default.
  46.  
  47.       -- setvar is used to give variables values.  All variables hold
  48.       -- string values, never numbers, i.e. "67" not 67.
  49.       -- Use variables to hold parameters that you may wish to change
  50.       -- later.
  51.  
  52.       setvar USERNAME "newton\r";   -- You must change this, of course.
  53.       setvar PHONE "ATDT4718454\r"; -- It's MY username, not yours.
  54.       setvar Modem_Escape_String "+++";  -- Some people change this.
  55.  
  56.       -- input prompts the user for a value for a variable.  The noecho
  57.       -- keyword causes what the user types to not be displayed.  Good 
  58.       -- for passwords.
  59.  
  60.       input PASSWORD noecho;   -- You could use a setvar here.
  61.  
  62.       next "ModemReady";         -- Branch to the state named ModemReady.
  63.  
  64.    end; -- init
  65.  
  66.    -- This state makes sure we have the (Hayes-type) modem's attention.
  67.    -- It sends a carriage return to it and expects it to reply with OK.
  68.  
  69.    state ModemReady
  70.  
  71.       -- The repeat statement executes the statements before its
  72.       --  end a fixed number of times, twice in this case.
  73.  
  74.       repeat 2
  75.  
  76.          -- send sends characters out over the serial port.  Note that
  77.          -- carriage return is not included automatically.  Use
  78.          -- \r for a carriage return.
  79.  
  80.          send "\r"; send "AT\r";
  81.  
  82.          -- select waits for one of several conditions.
  83.          select
  84.             "OK": next "Dial";  -- If OK is received, go to state Dial.               
  85.             timeout 3:  -- If 3 seconds pass without a match,
  86.                         -- display a message and exit the select.
  87.                 display "ModemReady timeout!\r";
  88.          end; -- select
  89.       end; -- repeat
  90.  
  91.       -- If we get here, the select has timed out in both
  92.       -- iterations of the repeat.  The modem is not responding.
  93.       -- Try hanging up.
  94.  
  95.       next "HangUp";  -- failed again, maybe hangup
  96.  
  97.    end; -- ModemReady
  98.  
  99.    -- The state hangs up a Hayes modem by sending +++, waiting for OK,
  100.    -- and then sending ATH.
  101.  
  102.    state HangUp
  103.  
  104.       repeat 2
  105.          -- Note that send pauses for one second before sending.
  106.          -- The delay does nothing for 1 second to give an even greater
  107.          -- pause before sending the escape string.
  108.          delay 1; send Modem_Escape_String;
  109.          select
  110.             "OK"      : send "ATH\r"; next "ModemReady";
  111.             timeout 3 : display "HangUp timeout!\r";
  112.          end;
  113.       end;
  114.       
  115.       -- If we reach this point, we have not received the ack for the
  116.       -- escape string.  We are confused and so try hanging up.
  117.       -- Control really should not reach this point.
  118.  
  119.       send "\r"; send "ATH\r";
  120.       next "ModemReady";
  121.  
  122.    end; -- HangUp
  123.  
  124.    -- This state dials the phone number and awaits the CONNECT message.
  125.    -- The select causes a redial if the line is busy, the modem responds
  126.    -- with NO CARRIER, or the modem does not respond with 25 seconds.
  127.  
  128.    state Dial
  129.       send PHONE;     -- The system's phone number
  130.       select
  131.          "CONNECT"    : next "GotIt";
  132.          "BUSY"       : next "ModemReady";
  133.          "NO CARRIER" : next "ModemReady";
  134.          timeout 25   : display "Dial timeout!\r"; next "ModemReady";
  135.       end; 
  136.    end; -- Dial
  137.  
  138.    -- This state enters the username and the password in reponse to
  139.    -- the appropriate prompts.  If there is no prompt within 60 seconds,
  140.    -- the script hangs up and redials.
  141.  
  142.    state GotIt
  143.  
  144.       -- Here is a trick.  The machine we are calling requires
  145.       -- that we send a break in order to switch to 2400 baud and prompt
  146.       -- for login.  The delay 1 gives a little time between the modem
  147.       -- connect and sending the break.  It is probably not necessary.
  148.  
  149.       delay 1;
  150.       send break;   -- UNIX host needs a break to switch to 2400 baud
  151.       select 
  152.          "login:"   : send USERNAME;
  153.          timeout 60 : display "login timeout!\r"; next "HangUp";
  154.       end;
  155.  
  156.       select
  157.          "Password:" : send PASSWORD; send "\r"; -- Your password
  158.          timeout 60  : display "password timeout!\r"; next "HangUp";
  159.       end;
  160.  
  161.       next "FinishUp";
  162.    end; -- GotIt
  163.  
  164.    -- This state is used to answer the terminal type prompt.  The nature
  165.    -- of this prompt depends on your .login file on UNIX.  You need to
  166.    -- to customize this state for your circumstances.  I enter return
  167.    -- to confirm that I will use a vt100 emulator and then switch to
  168.    -- the emulator I use (MacLayers) by means of the transfer.  
  169.    -- "RunLayers" is my settings file for MacLayers.  This script has
  170.    -- to be in the same folder as MacLayers and RunLayers in order
  171.    -- for the transfer to succeed.  The transfer quits DialScript and 
  172.    -- runs MacLayers with settings file RunLayers (as though I
  173.    -- had double clicked on RunLayers from the finder).
  174.  
  175.    state FinishUp   -- You need to customize this.  What's here is weak.
  176.       -- wait "(vt100)";                      -- Terminal type prompt
  177.       -- send "\r";                           -- Yes to vt100
  178.       -- transfer "MacLayers" "RunLayers";    -- Run real term emulator
  179.    end;  -- FinishUp
  180.  
  181.    -- FInally, the script ends with "end;" 
  182. end; -- cs
  183.